<?php
/**
 * +----------------------------------------------------------------------
 * | session处理处理类
 * +----------------------------------------------------------------------
 *                      _ooOoo_
 *                     o8888888o            | AUTHOR: 杜云
 *                     88" . "88            | EMAIL: 987772927@qq.com
 *                     (| -_- |)            | QQ: 987772927
 *                     O\  =  /O            | WECHAT: 987772927
 *                  ____/`---'\____
 *                .'  \\|     |//  `.
 *               /  \\|||  :  |||//  \
 *              /  _||||| -:- |||||-  \
 *              |   | \\\  -  /// |   |
 *              | \_|  ''\-/''  |   |
 *              \  .-\__  `-`  ___/-. /
 *            ___`. .'  /-.-\  `. . __
 *         ."" '<  `.___\_<|>_/___.'  >'"".
 *        | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *        \  \ `-.   \_ __\ /__ _/   .-` /  /
 *   ======`-.____`-.___\_____/___.-`____.-'======
 *                      `=-='
 * +----------------------------------------------------------------------
 */
declare(strict_types=1);
namespace Core\Common\Facade;

use Hyperf\Utils\ApplicationContext;
use Hyperf\Contract\SessionInterface;

class Session
{

    /**
     * setId
     * 设置sessionid
     * @param string $id
     */
    public static function setId(string $id)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        $session->setId($id);
        return ;
    }

    /**
     * getId
     * 获取sessionid
     */
    public static function getId()
    {
        $session =  ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->getId();
    }

    /**
     * set
     * 设置session
     * @param string $k
     * @param $v
     */
    public static function set(string $k,$v)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        $session->set($k,$v);
        return ;
    }

    /**
     * get
     * 获取session
     * @param string $k
     * @param null $default
     * @return mixed
     */
    public static function get(string $k,$default = null)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->get($k,$default);
    }

    /**
     * getAll
     * 获取所有session
     * @return mixed
     */
    public static function getAll()
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->all();
    }

    /**
     * has
     * 判断session是否存在
     * @param string $name
     * @return bool
     */
    public static function has(string $name)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->has($name);
    }

    /**
     * remove
     * 从 Session 中获取并删除一条数据
     * @param string $name
     * @return mixed
     */
    public static function remove(string $name)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->remove($name);
    }

    /**
     * forget
     * 从session中删除一条或多条数据
     * @param $keys string|array
     */
    public static function forget($keys)
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        $session->forget($keys);
        return;
    }

    /**
     * clear
     * 清空当前 Session 里的所有数据
     */
    public static function clear()
    {
        $session = ApplicationContext::getContainer()->get(SessionInterface::class);
        return $session->clear();
    }

}